<template>
	<el-dialog title="导出外联配置" :visible.sync="visible" width="800px" :center="false">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-upload" style="color: #FFF"></i>&nbsp;
			<span style="color: #FFF">导出外联配置</span>
		</div>

		<div>
			<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">
				<el-row>
					<el-col :span="12">

						<el-form-item label="开发地址:" :label-col="{ span: 24 }" :wrapper-col="{ span: 16  }"
							prop="esbSource">
							<el-select v-model="form.esbSource" style="width: 100%" placeholder="开发地址">
								<el-option v-for="item in esbEnvironmentList" :key="item.ip" :label="item.ip"
									:value="item.ip">
								</el-option>
							</el-select>

						</el-form-item>
					</el-col>
					<el-col :span="24">
						<!-- <el-form-item label="文件清单:" :label-col="{ span: 5 }" :wrapper-col="{ span: 16  }">

							<el-upload file-list="fileList" accept=".txt" :limit="1" multiple :auto-upload="false"
								action="#" :on-change="changeFile" style="text-align: left;">
								<!-- <i class="el-icon-upload"></i> -->
								<!-- <div class="el-upload__text">将版本清单拖到此处或<em>点击上传</em></div> 
								<el-button size="mini" type="success" style="width: 200px;"><i
										class="el-icon-upload" />点击上传</el-button>
								<div slot="tip" class="el-upload__tip">*只能上传txt文件</div>
							</el-upload>
						</el-form-item> -->
						<el-form-item label="文件清单:" :label-col="{ span: 24 }"
													:wrapper-col="{ span: 16  }" prop="file">
						
						<!-- <el-upload  file-list="fileList" accept=".txt" :limit="1" multiple :auto-upload="false" action="#" :on-change="changeFile" style="text-align: left;">
							<el-button size="mini" type="success" style="width: 200px;"><i class="el-icon-upload"/>点击上传</el-button>
							<div slot="tip" class="el-upload__tip">*只能上传txt文件</div>
						</el-upload> -->
						<el-input type="textarea"
						:rows="10"
						v-model="form.file">
						placeholder="eg:AHRCUApp/BusinessService/CBS/HTTPSRV_CBS_WLBZ_JSON_BusinessService"
							
						</el-input>
							</el-form-item>
					</el-col>
				</el-row>
			</el-form>


			<!-- 	<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">
				<el-row>
					<el-col :span="24">
						<el-col :span="24">
							<el-form-item label="文件清单:" prop="id" > -->

			<!-- 	</el-form-item> 
						</el-col>
					</el-col>
				</el-row>
			</el-form> -->
		</div>
		<span slot="footer" class="dialog-footer">
			<el-button @click="visible = false" size="mini">取 消</el-button>
			<el-button type="primary" @click="submit" size="mini" plain>确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
	"use strict";
	import {
		initFile,
		initOESBFile
	} from '@/api/release.js';
	import {
		getEsbEnvironmentByEsbFlg
	} from '@/api/environment.js';

	export default {
		data() {
			return {
				visible: false,
				/* fileList: [], */
				form: {
					qmsNo: '',
					batchNum: '',
					esbSource: '',
					file: ""
				},
				esbEnvironmentList: [],
				rules: {
					esbSource: [{
						required: true,
						message: '请选择开发环境',
						trigger: ['blur', 'change']
					}],
					/* file: [{
						required: true,
						message: '请输入文件清单',
						trigger: ['blur', 'change']
					}] */
				}
			}

		},

		created() {
			this.getEsbEnvironmentList();
		},
		methods: {
			getEsbEnvironmentList() {
				getEsbEnvironmentByEsbFlg({
					"esbFlg": "02"
				}).then(response => {
					this.esbEnvironmentList = response.data.extend;
				})
			},
			/* cancel(){
				this.visible = false;
				
				this.query = {};
			}, */
			ShowDialog(row) { 
				this.visible = true;
				Object.assign(this.form, row)
				/* this.fileList = [] */
				this.from.esbSource ='';
				this.from.file ='';
			},
			/* changeFile(file, fileList) {
				this.fileList = fileList;
			}, */
			submit() {
				this.$refs["form"].validate((valid) => {
					if (valid) {
						/* if (this.fileList.length == 1) {
							this.query.file = this.fileList[0].raw;
 */

							/* let data = new FormData();
							data.append("file", this.query.file);
							data.append("qmsNo", this.query.qmsNo);
							data.append("batchNum", this.query.batchNum);
							data.append("esbSource", this.query.esbSource);
 */
							initOESBFile(this.form).then(res => {

								let name = this.form.qmsNo+"_"+this.form.batchNum+"_OESB.zip";
								const blob = new Blob([res.data], {
									type: "application/zip"
								});
								const blobURL = window.URL.createObjectURL(blob);
								const aLink = document.createElement('a');
								aLink.href = blobURL;
								aLink.setAttribute('download', name);

								if (typeof aLink.download === 'undefined') {
									aLink.setAttribute('target', '_blank');
								}
								aLink.style.display = 'none';
								document.body.appendChild(aLink);
								aLink.click();
								document.body.removeChild(aLink);
								window.URL.revokeObjectURL(blob);
								this.$message({
						duration:5000,
									type: 'success',
									message: '生成文件成功'
								});
								this.visible = false;
							}).catch(error => {
								this.$message({
						duration:5000,									type: 'error',
									message: error
								});
							});


						/* } else {
							ththis.$message({
						duration:5000,							type: 'error',
								message: '请上传文件'
							});
						} */
					}
				});
			}

		}
	};
</script>
